<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>优田儿童成长中心</title>
    <!-- Styles -->
    <link href="/static/assets/fontAwesome/css/fontawesome-all.min.css" rel="stylesheet">
    <link href="/static/assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="/static/assets/css/lib/mmc-chat.css" rel="stylesheet"/>
    <link href="/static/assets/css/lib/sidebar.css" rel="stylesheet">
    <link href="/static/assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="/static/assets/css/lib/nixon.css" rel="stylesheet">
    <link href="/static/assets/lib/lobipanel/css/lobipanel.min.css" rel="stylesheet">
    <link href="/static/assets/css/style.css" rel="stylesheet">
    <script src="/static/js/jquery-1.11.0.js"></script>
</head>

<body>
<div class="sidebar sidebar-hide-to-small sidebar-shrink sidebar-gestures">
    <div class="nano">
        <div class="nano-content">
            <ul>
                <li><a href="/home/"><i class="ti-bar-chart"></i> 统计数据</a></li>
                <li><a href="/teacher/"><i class="ti-user"></i> 教师管理</a></li>
                <li class="active"><a href="/child/"><i class="ti-user"></i> 幼儿管理</a></li>
                <li><a href="/posts/"><i class="ti-desktop"></i> 岗位管理</a></li>
            </ul>
        </div>
    </div>
</div>

<div class="header">
    <div class="pull-left">
        <div class="logo">
            <a><img id="logoImg" src="/static/img/yt1.png" data-logo_big="/static/img/yt1.png"
                    data-logo_small="/static/img/yt3.png" alt="Nixon"/></a>
        </div>
        <div class="hamburger sidebar-toggle"><span class="ti-menu"></span></div>
    </div>
    <div class="pull-right p-r-15">
        <ul>
            <li class="header-icon dib">
                <img class="avatar-img" src="/static/assets/images/avatar/1.jpg" alt=""/> <span
                    class="user-avatar"><span th:text="${session.username}"></span>&nbsp;&nbsp;&nbsp;<i
                    class="ti-angle-down f-s-10"></i></span>
                <div class="drop-down dropdown-profile">
                    <div class="dropdown-content-body">
                        <ul>
                            <li><a href="/exit/"><i class="ti-power-off"></i><span>注销</span></a></li>
                        </ul>
                    </div>
                </div>
            </li>
        </ul>
    </div>
</div>

<div class="content-wrap">
    <div class="main">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-8 p-0">
                    <div class="page-header">
                        <div class="page-title">
                            <h1>幼儿管理</h1>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4 p-0">
                    <div class="page-header">
                        <div class="page-title">
                            <ol class="breadcrumb text-right">
                                <li><a href="/add_child/">添加幼儿</a></li>
                                <li class="active">幼儿管理</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>

            <div class="main-content">
                <div class="row">
                    <div class="card alert">
                        <div class="card-header">
                            <h4>添加幼儿</h4>
                        </div>
                        <div class="card-body">
                            <div class="basic-elements">
                                <form id="childForm">
                                    <div class="row">
                                        <div class="col-lg-6">
                                            <div class="form-group">
                                                <label>姓名</label>
                                                <input type="text" class="form-control" name="cname"
                                                       placeholder="请输入幼儿姓名" required>
                                            </div>
                                            <div class="form-group">
                                                <label>性别</label>
                                                <select class="form-control" name="csex" required>
                                                    <option value="男" selected>男</option>
                                                    <option value="女">女</option>
                                                </select>
                                            </div>
                                            <div class="form-group">
                                                <label>年龄</label>
                                                <input type="text" class="form-control" name="cage"
                                                       placeholder="请输入幼儿年龄" required>
                                            </div>
                                            <div class="form-group">
                                                <label>家长</label>
                                                <input type="text" class="form-control" name="cparnt"
                                                       placeholder="请输入家长姓名" required>
                                            </div>
                                            <div class="form-group">
                                                <label>联系方式</label>
                                                <input type="text" class="form-control" name="ctel"
                                                       placeholder="请输入联系方式" required>
                                            </div>
                                            <div class="form-group">
                                                <button type="button" id="submitChildBtn"
                                                        class="btn btn-success m-b-10 m-l-5">确认添加
                                                </button>
                                                <a href="/child/" class="btn btn-warning m-b-10 m-l-5">返回</a>
                                            </div>
                                        </div>
                                        <div class="col-lg-6">
                                            <div class="form-group">
                                                <img src="/static/img/child.png" width="500"/>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /# main content -->Copyright &copy; 2024
        </div>
    </div>
</div>

<!-- 脚本 -->
<script src="/static/assets/js/lib/jquery.min.js"></script>
<script src="/static/assets/js/lib/jquery.nanoscroller.min.js"></script>
<script src="/static/assets/js/lib/sidebar.js"></script>
<script src="/static/assets/js/lib/bootstrap.min.js"></script>
<script src="/static/assets/js/lib/mmc-common.js"></script>
<script src="/static/assets/js/lib/mmc-chat.js"></script>
<script src="/static/assets/js/lib/chart-js/Chart.bundle.js"></script>
<script src="/static/assets/js/lib/chart-js/chartjs-init.js"></script>
<script src="/static/assets/js/lib/datamap/d3.min.js"></script>
<script src="/static/assets/js/lib/datamap/topojson.js"></script>
<script src="/static/assets/js/lib/datamap/datamaps.world.min.js"></script>
<script src="/static/assets/js/lib/datamap/datamap-init.js"></script>
<script src="/static/assets/lib/lobipanel/js/lobipanel.js"></script>
<script src="/static/assets/js/scripts.js"></script>

<script>
    $(document).ready(function () {
        $('#lobipanel-custom-control').lobiPanel({
            reload: false,
            close: false,
            editTitle: false
        });

        $('#submitChildBtn').click(function () {
            const cname = $('input[name="cname"]').val().trim();
            const csex = $('select[name="csex"]').val();
            const cage = $('input[name="cage"]').val().trim();
            const cparnt = $('input[name="cparnt"]').val().trim();
            const ctel = $('input[name="ctel"]').val().trim();

            if (!cname || !cage || !cparnt || !ctel) {
                alert("请填写完整信息！");
                return;
            }

            $.ajax({
                type: "POST",
                url: "/api/v1/manager/child/save",
                data: {
                    cname: cname,
                    csex: csex,
                    cage: cage,
                    cparent: cparnt, // 修改这里
                    ctel: ctel,
                    flag: "1" // 加上这个参数
                },
                success: function (res) {
                    if (res.code === 200) {
                        alert("幼儿添加成功！");
                        window.location.href = "/child/";
                    } else {
                        alert("添加失败：" + res.message);
                    }
                },
                error: function () {
                    alert("提交失败，请检查网络或服务状态！");
                }
            });
        });
    });
</script>

<style>
    .copyrights {
        text-indent: -9999px;
        height: 0;
        line-height: 0;
        font-size: 0;
        overflow: hidden;
    }
</style>
<div class="copyrights">
    <h3>&copy; 版权所有</h3>
</div>

</body>
</html>
